package com.jbit.hxy.config;


import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;


@Getter
@Setter
@NoArgsConstructor
@ConfigurationProperties(prefix = "wx.miniapp")
public class MyWxMaConfig {

    /**
     * 微信小程序ID
     */
    private String appId;

    /**
     * 微信小程序密钥
     */
    private String appSecret;


    /**
     * 微信小程序配置信息Bean
     * @return
     */
    @Bean
    public WxMaConfig wxMaConfig(){
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(appId);
        wxMaConfig.setSecret(appSecret);
        wxMaConfig.setMsgDataFormat("JSON");
        return wxMaConfig;
    }

    /**
     * 微信小程序核心服务Bean
     * @return
     */
    @Bean
    public WxMaService wxMaService(){
        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaConfig());
        return wxMaService;
    }

}
